home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 101-125 / scopedisk106 / snag / snag.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  4KB  |  142 lines

  1. /* SNAG by Paul Falstad */
  2.  
  3. struct Library *GfxBase,*IntuitionBase;
  4.  
  5. main()
  6. {
  7. static struct NewScreen NewScreen = {
  8.    0,0,320,200,1,0,0,0,CUSTOMSCREEN,0,0,0,0 };
  9. static char buf[90],pbuf[10];
  10. static int daynum[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 };
  11. FILE *in;
  12. int t0,t1,t2,ot0,ot1,ot2;
  13. unsigned long tt,tim;
  14. long y = 20,loc;
  15. struct Screen *Screen;
  16.  
  17.    GfxBase = OpenLibrary("graphics.library",0L);
  18.    IntuitionBase = OpenLibrary("intuition.library",0L);
  19.    if (in = fopen("s:snag.dat","r+"))
  20.       while (!feof(in))
  21.          {
  22.          tim = time(0L);
  23.          loc = ftell(in);
  24.          fgets(buf,90,in);
  25.          if (*buf == '*')
  26.             break;
  27.          if (*buf == ';')
  28.             continue;
  29.          ot0 = t0 = (buf[41]-'0')*10+buf[42]-'0';
  30.          ot1 = t1 = (buf[44]-'0')*10+buf[45]-'0';
  31.          ot2 = t2 = (buf[47]-'0')*10+buf[48]-'0';
  32.          daynum[1] = (t2 % 4) ? 28 : 29;
  33.          if (t2 == 50)
  34.             {
  35. /*            if ((tim % 86400) > 79200)
  36.                tt = 0;
  37.             else */ /* doesn't work anymore */
  38.                tim = 0;
  39.             }
  40.          else
  41.             {
  42.             for (tt = 0, t2--; t2 >= 78; t2--)
  43.                {
  44.                if (t2 % 4)
  45.                   tt += 365L*24L*3600L;
  46.                else
  47.                   tt += 366L*24L*3600L;
  48.                }
  49.             for (t0--; t0 >= 1; t0--)
  50.                tt += daynum[t0-1]*24L*3600L;
  51.             tt += 24L*3600L*(t1-1);
  52.             }
  53.          if (tt+(3600*3) < tim)  /* wait till 3 am */
  54.             {
  55.             if (y == 20)
  56.                {
  57.                Screen = OpenScreen(&NewScreen);
  58.                sprintf(pbuf,"%6lx",Screen);
  59.                Move(&Screen->RastPort,0L,197L);
  60.                Text(&Screen->RastPort,pbuf,6L);
  61.                }
  62.             Move(&Screen->RastPort,0L,(long) (y += 10));
  63.             Text(&Screen->RastPort,buf,40L);
  64.             if (buf[49] == '*')
  65.                {
  66.                ot1 += 7;
  67.                if (ot1 > daynum[ot0-1])
  68.                   {
  69.                   ot1 -= daynum[ot0-1];
  70.                   if (++ot0 > 12)
  71.                      {
  72.                      ot0 -= 12;
  73.                      ot2++;
  74.                      }
  75.                   }
  76.                fseek(in,loc,0);
  77.                sprintf(&buf[41],"%02d-%02d-%02d*",ot0,ot1,ot2);
  78.                fwrite(buf,50,1,in);
  79.                fseek(in,loc+51,0);
  80.                }
  81.             if (buf[49] == ']')
  82.                {
  83.                ot1++;
  84.                if (ot1 > daynum[ot0-1])
  85.                   {
  86.                   ot1 -= daynum[ot0-1];
  87.                   if (++ot0 > 12)
  88.                      {
  89.                      ot0 -= 12;
  90.                      ot2++;
  91.                      }
  92.                   }
  93.                fseek(in,loc,0);
  94.                sprintf(&buf[41],"%02d-%02d-%02d]",ot0,ot1,ot2);
  95.                fwrite(buf,50,1,in);
  96.                fseek(in,loc+51,0);
  97.                }
  98.             if (buf[49] == '!')
  99.                {
  100.                ot1 += 14;
  101.                if (ot1 > daynum[ot0-1])
  102.                   {
  103.                   ot1 -= daynum[ot0-1];
  104.                   if (++ot0 > 12)
  105.                      {
  106.                      ot0 -= 12;
  107.                      ot2++;
  108.                      }
  109.                   }
  110.                fseek(in,loc,0);
  111.                sprintf(&buf[41],"%02d-%02d-%02d!",ot0,ot1,ot2);
  112.                fwrite(buf,50,1,in);
  113.                fseek(in,loc+51,0);
  114.                }
  115.             if (buf[49] == '&')
  116.                {
  117.                ot2++;
  118.                fseek(in,loc,0);
  119.                sprintf(&buf[41],"%02d-%02d-%02d&",ot0,ot1,ot2);
  120.                fwrite(buf,50,1,in);
  121.                fseek(in,loc+51,0);
  122.                }
  123.             if (buf[49] == '^')
  124.                {
  125.                ot0++;
  126.                if (ot0 > 12)
  127.                   {
  128.                   ot0 = 1;
  129.                   ot2++;
  130.                   }
  131.                fseek(in,loc,0);
  132.                sprintf(&buf[41],"%02d-%02d-%02d^",ot0,ot1,ot2);
  133.                fwrite(buf,50,1,in);
  134.                fseek(in,loc+51,0);
  135.                }
  136.             }
  137.          }
  138.    fclose(in);
  139.    CloseLibrary(IntuitionBase);
  140.    CloseLibrary(GfxBase);
  141. }
  142.